//
//  ShowViewController.m
//  One
//
//  Created by mac on 16-5-20.
//  Copyright (c) 2016年 mac. All rights reserved.
//

#import "ShowViewController.h"


@interface ShowViewController ()
{

}
@end

@implementation ShowViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    
    _backgroundView.backgroundColor = [UIColor whiteColor];
    _backgroundView.layer.cornerRadius = 10;
    _backgroundView.layer.masksToBounds = NO;
    
    _backgroundView.layer.shadowColor = [[UIColor colorWithWhite:0.611 alpha:1.000]CGColor];
    _backgroundView.layer.shadowOpacity = 0.5;
    _backgroundView.layer.shadowRadius = 4;
    
    _backgroundView.layer.shadowOffset = CGSizeMake(0,0);
    
    [self layoutShowView];
    
}

- (void)tap
{
    NSLog(@"showView");
}

- (void)layoutShowView
{
    if (!_hpObj) {
        return ;
    }
    
    else
    {
        [_hpImageView sd_setImageWithURL:[NSURL URLWithString:_hpObj.hp_img_url]];
        _hpImageView.userInteractionEnabled = YES;
        
        _hpContentLabel.text = _hpObj.hp_content;
        _hpTItleLabel.text = _hpObj.hp_title;
        _hpAuthorLabel.text = _hpObj.hp_author;
        if(WIDTH == 320)
            _hpAuthorLabel.font = [UIFont systemFontOfSize:9];
        else
            _hpAuthorLabel.font = [UIFont systemFontOfSize:12];
        
        NSString *dateStr = [self WeekWithMakeTime:_hpObj.hp_makettime];
        _timeLabel.text = dateStr;
        if (_hpObj.isFirst == NO) {
            _weatherImage.image = nil;
            _weatherAndCity.text = nil;
        }
        else
        {
            _weatherAndCity.text = _hpObj.cityName;
        }
    }
    
}

- (NSString *)WeekWithMakeTime:(NSString *)makeTime
{
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
    [dateFormatter setDateFormat:@"YYYY-MM-DD"];
    
    NSArray *arr = [makeTime componentsSeparatedByString:@" "];
    
    NSString *weekDay = arr[0];
    NSString *year = [weekDay componentsSeparatedByString:@"-"][0];
    int MonthDay = [[weekDay componentsSeparatedByString:@"-"][1] intValue];
    NSString *day = [weekDay componentsSeparatedByString:@"-"][2];
    
    NSDate *date = [dateFormatter dateFromString:weekDay];
    
    NSArray *weekArr = [NSArray arrayWithObjects:[NSNull null],@"Tue",@"Wed",@"Thu",@"Fri",@"Sat",@"Sun",@"Mon",nil];
    NSArray *monthArr = [NSArray arrayWithObjects:[NSNull null],@"Jan.",@"Feb.",@"Mar.",@"Apr.",@"May.",@"JUn.",@"Jul.",@"Aug.",@"Sep.",@"Oct.",@"Nov.",@"Dec.", nil];
    
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSCalendarUnit calendarUnit = NSCalendarUnitWeekday;
    NSDateComponents *theComponents = [calendar components:calendarUnit fromDate:date];
    NSString *week = [weekArr objectAtIndex:theComponents.weekday];
    NSString *mounth = monthArr[MonthDay];
    
    NSString *dateStr = [NSString stringWithFormat:@"%@ %@ %@ %@",week,day,mounth,year];
    
    return dateStr;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
